import "taro-ui/dist/style/components/checkbox.scss"
import { AtCheckbox } from "taro-ui"
import { AtCheckboxProps, CheckboxOption } from "taro-ui/types/checkbox"
import { useCallback, useEffect, useState } from "react"
import React from "react"
interface Props<T> extends Omit<AtCheckboxProps<T>, "selectedList"> {
	options: CheckboxOption<T>[]
	onChange: (val: T[]) => void
	defaultVal?: T[]
}
const TCheckBox: React.FC<Props<any>> = props => {
	const { onChange, defaultVal, options, ...config } = props
	const [val, setVal] = useState<any[]>()
	const valChange = useCallback(val => {
		setVal(val)
	}, [])
	useEffect(() => {
		val !== undefined && !!onChange && onChange(val)
	}, [val])
	return <AtCheckbox onChange={valChange} selectedList={val || defaultVal || []} options={options} {...config} />
}
export default TCheckBox
